package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.dto.LuntaiUserCarAndStore;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LuntaiUserCar;
import com.ruoyi.system.service.ILuntaiUserCarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户车辆信息Controller
 *
 * @author ruoyi
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/system/car")
public class LuntaiUserCarController extends BaseController {
    @Autowired
    private ILuntaiUserCarService luntaiUserCarService;

    /**
     * 查询用户车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:car:list')")
    @GetMapping("/list")
    public TableDataInfo list(LuntaiUserCar luntaiUserCar) {
        startPage();
        List<LuntaiUserCar> list = luntaiUserCarService.selectLuntaiUserCarList(luntaiUserCar);
        return getDataTable(list);
    }

    /**
     * 查询用户车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:car:list')")
    @PostMapping("/list2")
    public AjaxResult list2(@RequestBody LuntaiUserCar luntaiUserCar) {
        List<LuntaiUserCarAndStore> list = luntaiUserCarService.selectLuntaiUserCarList2(luntaiUserCar);
        return AjaxResult.success(list);
    }

    /**
     * 导出用户车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:car:export')")
    @Log(title = "用户车辆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LuntaiUserCar luntaiUserCar) {
        List<LuntaiUserCar> list = luntaiUserCarService.selectLuntaiUserCarList(luntaiUserCar);
        ExcelUtil<LuntaiUserCar> util = new ExcelUtil<LuntaiUserCar>(LuntaiUserCar.class);
        util.exportExcel(response, list, "用户车辆信息数据");
    }

    /**
     * 获取用户车辆信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:car:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(luntaiUserCarService.selectLuntaiUserCarById(id));
    }    /**
     * 获取用户车辆信息详细信息
     */
    @PostMapping("/getCarByCode")
    public AjaxResult getCarByCode(@RequestParam String code) {
        return success(luntaiUserCarService.getCarByCode(code));
    }


    /**
     * 新增用户车辆信息
     */
    @PreAuthorize("@ss.hasPermi('system:car:add')")
    @Log(title = "用户车辆信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody LuntaiUserCar luntaiUserCar) {
        return toAjax(luntaiUserCarService.insertLuntaiUserCar(luntaiUserCar));
    }

    /**
     * 修改用户车辆信息
     */
    @PreAuthorize("@ss.hasPermi('system:car:edit')")
    @Log(title = "用户车辆信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody LuntaiUserCar luntaiUserCar) {
        return toAjax(luntaiUserCarService.updateLuntaiUserCar(luntaiUserCar));
    }

    /**
     * 删除用户车辆信息
     */
    @PreAuthorize("@ss.hasPermi('system:car:remove')")
    @Log(title = "用户车辆信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(luntaiUserCarService.deleteLuntaiUserCarByIds(ids));
    }
}
